<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>优化节点添加</title>
</head>
<body>
    <script>
        // 优化前
        for(var i = 0; i< 10;i++) {
            var oP = document.createElement('p')
            op.innerHTML = i
            document.body.appendChild(op)
        }
        
        // 优化后
        const frageEle = document.createDocumentFragment()
        for(var i = 0;i<10;i++) {
            var oP = document.createElement('p')
            op.innerHTML = i
            frageEle.appendChild(op)
        }

        document.body.appendChild(frageEle)

    </script>
</body>
</html>